package cn.iocoder.yudao.module.biz.dal.mysql.staffCertificate;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.biz.dal.dataobject.staffCertificate.BizStaffCertificateDO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CustomBizStaffCertificateMapper extends BaseMapperX<BizStaffCertificateDO> {
    String querySql = "select bsc.*, bs.realname, sdd.label as certificateDept, bsw.name as workName from biz_staff_certificate bsc " +
            "left join biz_staff bs on bs.id = bsc.staff_id " +
            "left join system_dict_data sdd on sdd.dict_type='system_certificate_department' and bsc.certificate_dept = sdd.value " +
            "left join biz_special_work bsw on bsw.id = bsc.work_id ${ew.customSqlSegment} ";

    /**
     * 分页查询，不支持条件查询
     */
    @Select(querySql)
    List<BizStaffCertificateDO> list(Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper);

    /**
     * 分页查询，不支持条件查询
     */
    @Select(querySql)
    List<BizStaffCertificateDO> list(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    /**
     * 分页查询，支持Mybatis Plus条件查询
     */
    @Select(querySql)
    List<BizStaffCertificateDO> pageList(Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper);


    /**
     * 基础查询，注意是查询一条，需控制查询条件
     */
    @Select(querySql)
    BizStaffCertificateDO findOne(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    String countSql = "select count(bsc.id) from biz_staff_certificate bsc " +
            "left join biz_staff bs on bs.id = bsc.staff_id " +
            "left join system_dict_data sdd on sdd.dict_type='system_certificate_department' and bsc.certificate_dept = sdd.value " +
            "left join biz_special_work bsw on bsw.id = bsc.work_id ${ew.customSqlSegment} ";

    /**
     * 关联查询时获取数据数量
     * @param queryWrapper
     * @return
     */
    @Select(countSql)
    Long pageCount(@Param(Constants.WRAPPER) Wrapper queryWrapper);

}
